# 编写测试脚本
# 主要解决：
#     （1）测试数据
#     （2）断言
#     （3）关联

# 导包
from api.home import HomeAPI


# 创建测试类
class TestHomeAPI:
    # 前置处理
    def setup(self):
        # 实例化接口类
        self.home_api = HomeAPI()

    # 轮播图
    def test01_get_banner_info(self):
        # 获取响应数据
        response = self.home_api.get_banner_info()
        # 断言
        assert response.status_code == 200
        assert response.json().get("name") == "首页置顶"
        assert "首页轮播图" in response.text

    # 专题栏位
    def test02_get_theme_info(self):
        # 获取响应数据
        response = self.home_api.get_theme_info()
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json()[0].get("id") == 1
        assert "专题栏" in response.text

    # 最近新品
    def test03_get_recent_info(self):
        # 获取响应数据
        response = self.home_api.get_recent_info()
        print(response.json())
        # 断言
        assert response.status_code == 200
        assert response.json()[0].get("id") == 1
        assert "芹菜" in response.text

